package video.zerocopy;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class OldClient {

    public static void main(String[] args) throws Exception {

        SocketChannel socketChannel = SocketChannel.open();

        socketChannel.connect(new InetSocketAddress(8899));
        socketChannel.configureBlocking(true);

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024 * 1024 * 500);

        int readCount = 0;
        long startTime = System.currentTimeMillis();
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\58212\\Videos\\netty\\53_Netty对Executor的实现机制源码分析.flv");
        FileChannel fileChannel = fileInputStream.getChannel();
        while (readCount != -1) {
            readCount = fileChannel.read(byteBuffer);
            byteBuffer.flip();
            socketChannel.write(byteBuffer);
            byteBuffer.clear();
        }
        System.out.println("发送大小："+fileChannel.size()+"\t总耗时："+(System.currentTimeMillis()-startTime));
        fileChannel.close();
        fileInputStream.close();


    }
}
